package com.ewanghuiju.app.ui.home.fragment;

import android.graphics.drawable.GradientDrawable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.ViewFlipper;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.ewanghuiju.app.R;
import com.ewanghuiju.app.base.BaseFragment;
import com.ewanghuiju.app.base.BaseImmersionFragment;
import com.ewanghuiju.app.base.contract.home.ChoicesContract;
import com.ewanghuiju.app.presenter.home.ChoicesPresenter;
import com.ewanghuiju.app.test.bean.MyPageGridBean;
import com.ewanghuiju.app.test.bean.PintuanHomeBannerBean;
import com.ewanghuiju.app.util.SystemUtil;
import com.ewanghuiju.app.util.ToastUtil;
import com.stx.xhb.androidx.XBanner;
import com.wihaohao.PageGridView;

import java.util.ArrayList;
import java.util.List;

import androidx.viewpager.widget.ViewPager;
import butterknife.BindView;

/**
 * @author sj  qq:751943509
 * @class 精选页面
 * @time 2020/2/17
 */
public class ChoicestFragment2 extends BaseImmersionFragment {
//    @BindView(R.id.pageView)
//    PageGridView pageView;
    @BindView(R.id.xbanner)
    XBanner xbanner;
//    @BindView(R.id.vf_news)
//    ViewFlipper vfNews;
//    @BindView(R.id.tv_go_tuanzhang)
//    TextView tvGoTuanzhang;
//    @BindView(R.id.tv_go_water)
//    TextView tvGoWater;
//    @BindView(R.id.tv_jymarket)
//    TextView tvJymarket;



    @Override
    protected int getLayoutId() {
        return R.layout.fragment_choices2;
    }

    @Override
    protected void initEventAndData() {
        initBanner();
//        initPageGrid();
//        initViewFlipper();

//        GradientDrawable toTuanzhangGrad = (GradientDrawable) tvGoTuanzhang.getBackground();
//        GradientDrawable goWaterGrad = (GradientDrawable) tvGoWater.getBackground();
//        GradientDrawable jymarketGrad = (GradientDrawable) tvJymarket.getBackground();
//        toTuanzhangGrad.setStroke(SystemUtil.dp2px(1), getResources().getColor(R.color.color_371cda));
//        goWaterGrad.setStroke(SystemUtil.dp2px(1), getResources().getColor(R.color.color_da1cd3));
//        jymarketGrad.setColor(getResources().getColor(R.color.transparent));
//        jymarketGrad.setStroke(SystemUtil.dp2px(1), getResources().getColor(R.color.white));
    }

    /**
     * 加载banner
     */
    public void initBanner() {
        //测试数据  测试bean
        List<PintuanHomeBannerBean> bannerList = new ArrayList<>();
        PintuanHomeBannerBean bean = new PintuanHomeBannerBean();
        bean.setResId(R.mipmap.bg_splash);
        bannerList.add(bean);
        bean = new PintuanHomeBannerBean();
        bean.setResId(R.mipmap.bg_splash);
        bannerList.add(bean);
        bean = new PintuanHomeBannerBean();
        bean.setResId(R.mipmap.bg_splash);
        bannerList.add(bean);
        xbanner.setBannerData(R.layout.banner_item_with_corner, bannerList);
        //加载广告图片
        xbanner.loadImage(new XBanner.XBannerAdapter() {
            @Override
            public void loadBanner(XBanner banner, Object model, View view, int position) {
                ImageView riv = view.findViewById(R.id.banner_image);
                Glide.with(context).load(R.mipmap.test_banner).skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).into(riv);
            }
        });
        xbanner.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                if (position == 0) {

                } else {

                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

//    /**
//     * 网格翻页
//     */
//    private void initPageGrid() {
//        List<MyPageGridBean> classifyList = new ArrayList<>();
//        for (int i = 0; i < 15; i++) {
//            MyPageGridBean bean = new MyPageGridBean();
//            bean.setTitle("淘宝");
//            bean.setImg(R.mipmap.icon_taobao);
//            classifyList.add(bean);
//        }
//        pageView.setData(classifyList);
//        pageView.setOnItemClickListener(new PageGridView.OnItemClickListener() {
//            @Override
//            public void onItemClick(int position) {
//                ToastUtil.show("" + position);
//            }
//        });
//    }
//
//    private void initViewFlipper() {
//        List<String> listStr = new ArrayList<>();
//        listStr.add("1由于疫情影响快递延迟发货");
//        listStr.add("2由于疫情影响快递延迟发货");
//        listStr.add("3由于疫情影响快递延迟发货");
//        listStr.add("4由于疫情影响快递延迟发货");
//        listStr.add("5由于疫情影响快递延迟发货");
//        for (int i = 0; i < listStr.size(); i++) {
//            TextView itemTextView = (TextView) View.inflate(context, R.layout.item_ewnews_viewflipper, null);
//            itemTextView.setText(listStr.get(i));
//            vfNews.addView(itemTextView);
//        }
//    }
//
//    @Override
//    public void showContent(String list) {
//
//    }
//
//    @Override
//    public void showMoreContent(String list) {
//
//    }
}
